<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>编辑用户</title>
<link rel="stylesheet" href="/css/bootstrap.min.css">
	<script src="/js/jquery/jquery.min.js"></script>
	<script src="/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
	<script src="/js/jquery.validation/1.14.0/messages_zh.min.js"></script>
<style type="text/css">
	input.error{
		border:1px solid #E6594E;
	}
</style>
</head>
<body>
	<div class="container">
		<form id="editUserForm">
			<br/>
			<div class="form-group">
				<label for="loginName">用户名称</label>
				<input type="text" name="loginName" id="loginName" class="form-control" value="${data.loginName}"/>
			</div>
			<div class="form-group">
				<label for="loginPassword1">原用户密码</label>
				<input type="text" name="loginpassword1" id="loginPassword1" class="form-control" value="${data.loginPassword}"/>
			</div>
			<div class="form-group">
				<label for="loginPassword">新密码</label>
				<input type="password" name="loginPassword" id="loginPassword" class="form-control" placeholder="输入新密码"/>
			</div>
			<div class="form-group">
				<label for="loginPassword2">确认密码</label>
				<input type="password" name="loginPassword2" id="loginPassword2" class="form-control" placeholder="再次输入新密码"/>
			</div>
			<div class="form-group">
				<label for="truthName">真实名称</label>
				<input type="text" name="truthName" id="truthName" class="form-control" value="${data.truthName}"/>
			</div>
			<div class="form-group">
				<label for="phone">用户电话</label>
				<input type="text" name="phone" id="phone" class="form-control" value="${data.phone}"/>
			</div>
			<div class="form-group">
				<button type="button" id="saveBtn" class="btn btn-success">提交</button>
				<button type="button" id="cancelBtn" class="btn btn-default">取消</button>
			</div>
		</form>
	</div>
		<script>
		var editUser=function(){
			if(!check().form()){ 
					return;  
				}
			$.ajax({
				type:"GET",
				dataType:"json",
				url:"/user/edit",
				data:{
					"userId":${data.userId},
					"loginName":$("#loginName").val(),
					"loginPassword":$("#loginPassword").val(),
					"truthName":$("#truthName").val(),
					"phone":$("#phone").val()
				},
				success:function(msg){
					$("#cancelBtn").click();//请求成功并返回信息
				}
			});
		}
			
			$('#saveBtn').on('click', function(){
				editUser();
			});
			
			$('#cancelBtn').on('click', function(){
				var index = parent.layer.getFrameIndex(window.name);
				parent.getUserPageList();
				parent.layer.close(index);
			});

			
			//校验字段是否正确 
            function check(){ 
                /*返回一个validate对象，这个对象有一个form方法，返回的是是否通过验证*/ 
                return $("#editUserForm").validate({ 
                            rules:{ 
                                loginName:{ 
                                    required:true
                                },
                                loginPassword:{ 
                                    required:true                                   
                                },
                                loginPassword2:{
                                	required:true
                                },
                                truthName:{
                                	required:true
                                },
                                phone:{
                                	required:true
                                }
                            }, 
                            messages:{ 
                                loginName:{ 
                                    required:""
                                },
                                loginPassword:{ 
                                    required:""                                
                                },
                                loginPassword2:{
                                	required:""
                                },
                                truthName:{
                                	required:""
                                },
                                phone:{
                                	required:""
                                }
                            }     
                        }); 
            } 
		</script> 	
</body>
</html>